class_name StartBattleButton
extends Button

# ===============================================

@export var game_state: GameState
@export var player_stats: PlayerStats
@export var arena_grid: UnitGrid

# ===============================================

@onready var icon_texture: TextureRect = $Icon

# ===============================================

func __update() -> void:
	var units_used: int = arena_grid.get_all_units().size()
	disabled = game_state.is_battling() or units_used > player_stats.level or units_used == 0
	if disabled:
		icon_texture.modulate.a = 0.5
	else:
		icon_texture.modulate.a = 1.0

# ===============================================

func _ready() -> void:
	pressed.connect(
		func():
			if game_state.is_battling():
				return
			game_state.state = GameState.State.BATTLE
			disabled = true
	)
	game_state.changed.connect(__update)
	player_stats.changed.connect(__update)
	arena_grid.unit_grid_changed.connect(__update)
	__update()
